<?
require_once('ArrayConverter.php');

class ArrayConverterTest extends PHPUnit_Framework_TestCase {
	protected $c;
	protected function setUp() {
		$this->c= new ArrayConverter;
	}
	function testDefaultDelimiter() {
		$this->assertEquals(';',$this->c->getDelimiter());
	}
	function testGetAsString() {
		$this->assertEquals('',$this->c->getAsString(null));
		$this->assertEquals('',$this->c->getAsString(array()));
		$this->assertEquals('1;2;3',$this->c->getAsString(array(1,2,3)));
		$this->assertEquals('1;2;3',$this->c->getAsString(array('1','2','3')));

		$this->setExpectedException('ConverterException');
		$this->c->getAsString(new ArrayConverter());
		$this->setExpectedException('ConverterException');
		$this->c->getAsString(1);
		$this->setExpectedException('ConverterException');
		$this->c->getAsString('test');
	}

	function testGetAsDatatype() {
		$this->assertNull($this->c->getAsDatatype(null));

		$this->assertEquals(0,count($this->c->getAsDatatype('')));
		$this->assertEquals(
			array('first','second'),
			$this->c->getAsDatatype('first;second')
		);
	}

	function testChangeDelimiter() {
		$this->c->setDelimiter('-');
		$this->assertEquals(
			array('before','first','second'),
			$this->c->getAsDatatype('before-first-second')
		);
		$this->assertEquals(
			'1-2-3',
			$this->c->getAsString(array(1,2,3))
		);
	}
}
